package com.qf.fmall2203.index.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2203.index.entity.Category;
import com.qf.fmall2203.index.entity.IndexImg;
import com.qf.fmall2203.index.entity.Product;
import com.qf.fmall2203.index.entity.ProductImg;
import com.qf.fmall2203.index.mapper.IndexImgMapper;
import com.qf.fmall2203.index.service.IIndexImgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.fmall2203.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.ls.LSException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * <p>
 * 轮播图  服务实现类
 * </p>
 *
 * @author ljc
 * @since 2023-02-13
 */
@Service
public class IndexImgServiceImpl extends ServiceImpl<IndexImgMapper, IndexImg> implements IIndexImgService {

    @Autowired
    IndexImgMapper indexImgMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public ResultVo getIndex() {

       List<IndexImg> indexImgs =  indexImgMapper.selectAll();


        return ResultVo.ok(indexImgs);
    }

    @Override
    public ResultVo getListR() {

         List<Product> list =   indexImgMapper.getListR();

        for (Product product : list) {

            List<ProductImg> list1 = indexImgMapper.getImage(product.getProductId());

            product.setImgs(list1);

        }

         ResultVo.ok(list);

        return  ResultVo.ok(list);
    }


    @Override
    public ResultVo getCategoryList() {

        List<Category> list = indexImgMapper.getOneLevel();

        for (Category category : list) {
            List<Category> list1 = indexImgMapper.getTowLevel(category.getCategoryId());
            category.setCategories(list1);
            for (Category category1 : list1) {
                List<Category> list2 = indexImgMapper.getThreeLevel(category1.getCategoryId());
                category1.setCategories(list2);
            }
        }

        return ResultVo.ok(list);

    }

    @Override
    public ResultVo getCategoryRecommends() {
        List<Category> oneLevel = indexImgMapper.getOneLevel();

        for (Category category : oneLevel) {

          List<Product> products =   indexImgMapper.getOneLevelProducts(category.getCategoryId());

            for (Product product : products) {

                List<ProductImg> image = indexImgMapper.getImage(product.getProductId());

                product.setImgs(image);
            }

          category.setProducts(products);
        }

        return ResultVo.ok(oneLevel);


    }


}
